var myiscroll=null;
//审核人
var chinName="";
var rpstatus="";
var reportDate="";
$(document).ready(function(){
	$("#loading").show();
	$("#content").hide();
	/*
	 * 查询数据 得到日期
	 */
	//解析url,获取汇报日期
	/*
    var url = location.href.split('?')[1];
	if(url!=null){
		var arr = url.split('&');
		for(var i = 0 ; i < arr.length;i++){
			var temp = arr[i];
			var tempArr = temp.split('=');
			var key = tempArr[0];
			if(key == "report_date"){
				reportDate=tempArr[1];
			}
		}
	}*/
	reportDate = getQueryParam("report_date");
	$("#reportDate").text("我的"+reportDate.split("/")[1]+"月汇报");
	$.ajax({
		type:"post",
		url:mpsurl+"/mobile/report/queryMyReportGrade.do",
		dateType:"json",
		data:{report_date:reportDate},
		success:function(data){//关键工作计划项
			$("#loading").hide();
			$("#content").show();
			var obj=eval("("+data+")");
			
			if(obj.resultCode=="500600"){
				var div="";
				var	count=0;
				var reportStatus=obj.value.report.pAIC_MON_STATUS;
				rpstatus = obj.value.report.pAIC_MON_STATUS;
				chinName = obj.value.report.manager1_name;
				/** 解析状态*/
				var staArr = {"USUB":"未提交","SUBM":"待确认","APP":"已确认","BAC":"已驳回","NON":"未制定"};
				for(var perSta in staArr){
					if(perSta == reportStatus){
						reportStatus = staArr[perSta];
					}
				}
				$("#status").text(reportStatus);
				var ewglen = obj.value.ewg.length;
				//关键计划评分为空，不显示关键计划
				if (ewglen==0){
					$("#ewglist").hide();
				}else{
					if(obj.value.ewg[0].iscyc=="0"){
						$("#ewglist").hide();
					}else{
						for(var i=0;i<obj.value.ewg.length;i++){
							/*
							 * 权重，自评分，领导评分
							 */
							 var strewg="";
							if(rpstatus=="APP") 
								strewg=obj.value.ewg[i].ewg_oth_rating;
							div=$("<li>" +
									 "<div class=\"score-table-td\">"+
									 "<div class=\"row-left-icon\"><i>"+(i+1)+"</i></div>"+
									 "<div class=\"info-list-cont\">"+obj.value.ewg[i].ewg_descr+"</div>"+
									 "</div>" +
									 "<div class=\"score-table-td\">"+obj.value.ewg[i].ewg_weight+"%</div>"+
									 "<div class=\"score-table-td\">"+obj.value.ewg[i].ewg_self_rating+"</div>" +
									 "<div class=\"score-table-td\">"+strewg+"</div>" +
								  "</li>");
							$("#row-info-list").append(div);
						}
					}
				}
				var reportGrade = obj.value.reportGrade;
				var report = obj.value.report;
				var manager1_name = report.manager1_name;
				var manager2_name = report.manager2_name;
				var manager3_name = report.manager3_name;
				if(reportGrade.length!=0){
					if(ewglen!=0 || obj.iscyc=="1"){
						if(reportGrade.self_grade100.indexOf(".")<0)
							reportGrade.self_grade100 = reportGrade.self_grade100+".00";
						if(reportGrade.assess1_grade100.indexOf(".")<0)
							reportGrade.assess1_grade100 = reportGrade.assess1_grade100+".00";
						var strzp ="";
						if(report.pAIC_MON_STATUS=="APP")
							strzp = reportGrade.assess1_grade100;
						/** 总评分*/
						var endli="<li>"+"<div class=\"score-table-td\"></div>"+
			  			 		  "<div class=\"score-table-td\">总评分</div>"+
			  			 		  "<div class='score-table-td'>"+reportGrade.self_grade100+"</div><div class='score-table-td'><label id='otherTotaleGrade'>"+strzp+"</label></div></li>";
			      		 		  "</li>"
			   		 	$("#row-info-list").append(endli);
		   		 	}
		   		 	//自评分
		   		 	var zpf = $("<li>"+
			             "<div class=\"info-list-cont\"><span class=\"fn-c-999\">自评分：</span>"+reportGrade.self_grade5+"</div>"+
			             "</li>");
			        $("#row-info-list-ul").append(zpf);
					/** 下半部分（考核人的意见和评分）*/
					//汇报状态：已确认，显示考核人意见和评分
					if(report.pAIC_MON_STATUS=="APP"){
						var div2=$("<li>"+
			                       "<div class=\"info-list-cont\">"+
			                       "<p>主考核人："+manager1_name+" <span class=\"fn-c-999\">评分：</span><span class=\"fn-c-fa4043\">"+reportGrade.assess1_grade5+"</span></p>"+
			                       "<p><span class=\"fn-c-999\">意见：</span>"+reportGrade.assess1.replace(/\n/g,"<br>")+"</p>"+
			                   	   "</div>"+
			                	   "</li>"
			                	   );
						$("#row-info-list-ul").append(div2);
					}
					if(report.ep_manager2_status=="Y"){
						var eP_MANAGER2_ID = report.eP_MANAGER2_ID;
						if(eP_MANAGER2_ID.replace(/(^\s*)|(\s*$)/g, "")!=""){
							div2 = $("<li>"+
								   "<div class=\"info-list-cont\">"+
			                       "<p>第二考核人："+manager2_name+" <span class=\"fn-c-999\">评分：</span><span class=\"fn-c-fa4043\">"+reportGrade.assess2_grade5+"</span></p>"+
			                       "<p><span class=\"fn-c-999\">意见：</span>"+reportGrade.assess2.replace(/\n/g,"<br>")+"</p>"+
			                       "</div></li>");
			                $("#row-info-list-ul").append(div2);
						}
					}
					if(report.ep_manager3_status=="Y"){
						/** 如果有第三审核人 就显示!*/
						if(report.eP_MANAGER3_ID.replace(/(^\s*)|(\s*$)/g, "")!=""){
					          var div3=$("<li><div class=\"info-list-cont\">"+
					          "<p>第三考核人："+manager3_name+" <span class=\"fn-c-999\">评分：</span><span class=\"fn-c-fa4043\">"+reportGrade.assess3_grade5+"</span></p>"+
					          "<p><span class=\"fn-c-999\">意见：</span>"+reportGrade.assess3.replace(/\n/g,"<br>")+"</p>"+
					          "</div></li>");
					          $("#row-info-list-ul").append(div3);
					    }
				    }
			     }
				//滚动条
				iscroll();
			}else{
				var tourl = "/mobile/myreport/wdydbg2-chakan.html?report_date="+reportDate;
            	checkLogin(obj.resultCode,tourl,obj.resultMessage);
			}
		},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				$("content").show()
				$("#loading").hide();
				//errorMask(errorThrown||"请求失败");
				setPromptForInput("网络异常");
			}
	});
	
	/*
	 * 点击返回后 将日期传回去！
	 */
	$("#domwBack").on("tap", function(){
		//location.href="/mobile/myreport/wdydbg-chakan.html?report_date="+ reportDate;
		var param = "report_date="+ reportDate;
		gotoLocation("/mobile/myreport/wdydbg-chakan.html",param);
	});
	$("#errorMask").tap(function(){
		$("#errorMask").hide();
	});
	
	//汇报状态提示
    $("#status").on("tap",function(){
    	var month="";
    	month = reportDate.substr(5,2);
    	var message="";
    	if(rpstatus=="USUB")
    		message="您的"+month+"月汇报还未提交，提交后将由"+chinName+"审批。";
    	else if(rpstatus=="SUBM")
    		message="您的"+month+"月汇报已提交，将由"+chinName+"确认。";
    	else if(rpstatus=="APP")
    		message="您的"+month+"月汇报已由"+chinName+"确认。";
    	else if(rpstatus=="BAC")
    		message="您的"+month+"月汇报已被"+chinName+"驳回，重新提交后将由"+chinName+"审批";
    	else if(rpstatus=="NON")
    		message="您的"+month+"月汇报还未制定，制定后将由"+chinName+"审批。";
    	errorMask(message);
    });
});
function iscroll(){
	var wh = $(window).height()-90; 
	if(myiscroll instanceof iScroll)
		myiscroll.destroy();
	$("#content").css("height",wh+"px");
	myiscroll = new iScroll("content",{bounce:false});
}